package org.malred.hospital.controller;

import org.malred.hospital.common.R;

import org.malred.hospital.entity.TbStudentAccount;
import org.malred.hospital.entity.TbStudentAccount;
import org.malred.hospital.entity.TbStudentAccount;
import org.malred.hospital.service.StudentAccountService;
import org.malred.hospital.service.StudentAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//@CrossOrigin(origins = "*",maxAge = 3600)
@RestController
@RequestMapping("/student-account")
public class StudentAccountController extends BaseController<TbStudentAccount> {
    @Autowired
    private StudentAccountService service;

    @Override
    public R<List<TbStudentAccount>> findAll() {
        return R.success(service.list());
    }

    @Override
    public R<TbStudentAccount> findById(Long id) {
        return R.success(service.getById(id));
    }

    @Override
    public R<TbStudentAccount> insert(@RequestBody TbStudentAccount dto) {
        if (service.save(dto)) {
            return R.success(dto);
        } else {
            return R.error("添加 [StudentAccount] 失败");
        }
    }

    @Override
    public R<TbStudentAccount> update(@RequestBody TbStudentAccount dto) {
        if (service.save(dto)) {
            return R.success(dto);
        } else {
            return R.error("修改 [StudentAccount] 失败");
        }
    }

    @Override
    public R<TbStudentAccount> delete(Long id) {
        if (service.removeById(id)) {
            return R.success(null);
        } else {
            return R.error("删除 [StudentAccount] 失败");
        }
    }
}
